/*
 * MisMain.java
 *
 * Created on 27 de noviembre de 2006, 03:04 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package pruebas;

import ig.ejb.metrica.da.session.editor.EditorRemote;
import ig.ejb.metrica.da.session.editor.EditorRemoteHome;
import ig.ejb.metrica.da.session.editor.dto.ColumnaDTO;
import ig.ejb.metrica.da.session.editor.dto.TablaDTO;
import ig.util.ejb.IGBean;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;

public class Main {

    public static void main(String[] arg) throws Exception {
        List<TablaDTO> tablaDTOs =  lookupModeloSBean().getAllTables();
        for (TablaDTO tablaDTO : tablaDTOs) {
            System.out.println(tablaDTO.getNombre());
            List<ColumnaDTO> columnaDTOs = (lookupModeloSBean().getColumnTables(tablaDTO.getNombre()));
            for (ColumnaDTO columnaDTO : columnaDTOs) {
                System.out.println("  "+columnaDTO.getNombre());
            }
            System.out.println("-----------------------------------------------");
        }
    }

    private static EditorRemote lookupModeloSBean() {
        try {

            Properties prop = new Properties();
            prop.put(Context.INITIAL_CONTEXT_FACTORY, IGBean.INITIAL_CONTEXT_FACTORY);
            String Sockec = "localhost:1099";
            prop.put(Context.PROVIDER_URL, Sockec);

            javax.naming.Context c = new javax.naming.InitialContext(prop);
            Object remote = c.lookup("EditorSBean");
            EditorRemoteHome rv = (EditorRemoteHome) javax.rmi.PortableRemoteObject.narrow(remote, EditorRemoteHome.class);
            return rv.create();

        } catch (javax.naming.NamingException ne) {
            throw new RuntimeException(ne);
        } catch (javax.ejb.CreateException ce) {
            throw new RuntimeException(ce);
        } catch (java.rmi.RemoteException re) {
            throw new RuntimeException(re);
        }
    }
}